/*Copyright (C),2023 , NANOCHAP
*File name:             
*Author:      Martin
*Version:     V1.0 
*Date:        2023-08-11                  
*Description: 
*Function List: 
   1. 
   2.
   3.
History: 
   1.V1.0
      Date:          
      Author: 
      Modification:
*/
#include "CMSDK_CM0.h"
#include "MY_HEADER.h"


//IO口输入输出设置,形参1：gpio号，形参2：输入输出选择 ，形参3：使能与否
uint8_t GPIO_I_O_Select(GPIO_NUM GPIO_X, I_O_SELECT INorOUT ,FunctionalState ENABLEorNOT){
	if(INorOUT == INPUT && ENABLEorNOT ==ENABLE)
	{
		CMSDK_GPIO->OE &=~ (1<<GPIO_X);
		CMSDK_GPIO->IE |= (1<<GPIO_X);
	}
	else if(INorOUT == INPUT && ENABLEorNOT ==DISABLE)
	{
		CMSDK_GPIO->OE &=~ (1<<GPIO_X);
		CMSDK_GPIO->IE &=~ (1<<GPIO_X);
	}
	else if(INorOUT == OUTPUT && ENABLEorNOT ==ENABLE)
	{
		CMSDK_GPIO->IE &=~ (1<<GPIO_X);
		CMSDK_GPIO->OE |= (1<<GPIO_X);
	}
	else if(INorOUT == OUTPUT && ENABLEorNOT == DISABLE)
	{
		CMSDK_GPIO->OE &=~ (1<<GPIO_X);
		CMSDK_GPIO->IE &=~ (1<<GPIO_X);
	}
	else 
		return -1;
}

//读取IO口输入状态
uint8_t GPIO_GetInputValue(GPIO_NUM GPIO_X){ 
	return (uint8_t)(CMSDK_GPIO->DATAIN & (1<<GPIO_X));
}

//读取IO口输出状态
uint8_t GPIO_GetOutputValue(GPIO_NUM GPIO_X){ 
	return (uint8_t)(CMSDK_GPIO->DATAOUT & (1<<GPIO_X));
}

//设置输出电平为高或低
void GPIO_SetOutputValue(GPIO_NUM GPIO_X,LEVELStatus HIGHorLOW){
	if(value == HIGH_LEVEL)
	{
		CMSDK_GPIO->DATAOUT |= (1<<GPIO_X);
	}
	else 
	{
		CMSDK_GPIO->DATAOUT &=~ (1<<GPIO_X);
	}
}

//设置输出电平为高
void GPIO_SetOutputValue(uint8_t GPIO_X){
	CMSDK_GPIO->BITSET |= (1<<GPIO_X);
}

//设置输出电平为低
void GPIO_ClrOutputValue(uint8_t GPIO_X){
	CMSDK_GPIO->BITCLR |= (1<<GPIO_X);
}

//设置IO上拉下拉
void 






 void CMSDK_gpio_ClrAltFunc(CMSDK_GPIO_TypeDef *CMSDK_GPIO, uint32_t AltFuncclr)
 {
       CMSDK_GPIO->ALTFUNCCLR = AltFuncclr;
 }

 uint32_t CMSDK_gpio_GetAltFunc(CMSDK_GPIO_TypeDef *CMSDK_GPIO)
 {
       return CMSDK_GPIO->ALTFUNCSET;
 }


 uint32_t CMSDK_gpio_IntClear(CMSDK_GPIO_TypeDef *CMSDK_GPIO, uint32_t Num)
 {
       CMSDK_GPIO->INTCLEAR = (1 << Num);

       return CMSDK_GPIO->INTSTATUS;
 }


 uint32_t CMSDK_gpio_SetIntEnable(CMSDK_GPIO_TypeDef *CMSDK_GPIO, uint32_t Num)
 {
       CMSDK_GPIO->INTENSET = (1 << Num);

       return CMSDK_GPIO->INTENSET;
 }


  uint32_t CMSDK_gpio_ClrIntEnable(CMSDK_GPIO_TypeDef *CMSDK_GPIO, uint32_t Num)
 {
       CMSDK_GPIO->INTENCLR = (1 << Num);

       return CMSDK_GPIO->INTENCLR;
 }


 void CMSDK_gpio_SetIntHighLevel(CMSDK_GPIO_TypeDef *CMSDK_GPIO, uint32_t Num)
 {
       CMSDK_GPIO->INTTYPECLR = (1 << Num); /* Clear INT TYPE bit */
       CMSDK_GPIO->INTPOLSET = (1 << Num);  /* Set INT POLarity bit */
 }


 void CMSDK_gpio_SetIntRisingEdge(CMSDK_GPIO_TypeDef *CMSDK_GPIO, uint32_t Num)
 {
       CMSDK_GPIO->INTTYPESET = (1 << Num); /* Set INT TYPE bit */
       CMSDK_GPIO->INTPOLSET = (1 << Num);  /* Set INT POLarity bit */
 }


 void CMSDK_gpio_SetIntLowLevel(CMSDK_GPIO_TypeDef *CMSDK_GPIO, uint32_t Num)
 {
       CMSDK_GPIO->INTTYPECLR = (1 << Num);  /* Clear INT TYPE bit */
       CMSDK_GPIO->INTPOLCLR = (1 << Num);   /* Clear INT POLarity bit */
 }


 void CMSDK_gpio_SetIntFallingEdge(CMSDK_GPIO_TypeDef *CMSDK_GPIO, uint32_t Num)
 {
       CMSDK_GPIO->INTTYPESET = (1 << Num);  /* Set INT TYPE bit */
       CMSDK_GPIO->INTPOLCLR = (1 << Num);   /* Clear INT POLarity bit */
 }